﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace SharpMoney.Library
{
	public struct Currency
	{
		#region Variables

		private string _code;
		private string _symbol;
		private string _name;

		#endregion

		#region Properties

		public string Code
		{
			get
			{
				return _code;
			}
			set
			{
				_code = value;
			}
		}

		public string Symbol
		{
			get
			{
				return _symbol;
			}
			set
			{
				_symbol = value;
			}
		}

		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		public static Currency Default
		{
			get
			{
				return new Currency(
					RegionInfo.CurrentRegion.ISOCurrencySymbol,
					RegionInfo.CurrentRegion.CurrencySymbol,
					RegionInfo.CurrentRegion.CurrencyEnglishName
				);
			}
		}

		#endregion

		#region Constructors

		public Currency( string code )
			: this( code, null, null )
		{
		}

		public Currency( string code, string symbol )
			: this( code, symbol, null )
		{
		}

		public Currency( string code, string symbol, string name )
		{
			this._code = code;
			this._symbol = symbol;
			this._name = name;
		}

		#endregion

		#region Base Class Overrides

		public override string ToString()
		{
			return this._symbol;
		}

		public override bool Equals( object obj )
		{
			return base.Equals( obj );
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		#endregion

		#region Operator Overloads

		public static bool operator ==( Currency a, Currency b )
		{
			return a.Code == b.Code;
		}

		public static bool operator !=( Currency a, Currency b )
		{
			return a.Code != b.Code;
		}

		#endregion

		#region Implicit Operator Overloads

		public static implicit operator Currency( string code )
		{
			return new Currency( code );
		}

		public static implicit operator Currency( Money value )
		{
			return new Currency(
				value.Currency.Code,
				value.Currency.Symbol,
				value.Currency.Name
			);
		}

		#endregion
	}
}
